import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;

import Images;
class PauseMenuEvent extends Event{
 
	public function new(customEventString:String){

	super(customEventString, true, false);

    }
}

class PauseMenu extends Sprite
{
private var VolumeButton:Sprite;
private var SoundEffectsButton:Sprite;
private var CurrentBackground: Sprite;
private var MainMenu:Sprite;
private var Text:TextField;

// public var volume:Bool;
// public var sound:Bool;

  public function new()
  {
  super();
  //Resize Image
  CurrentBackground = new Sprite();
  CurrentBackground.graphics.beginFill(0x000000);
  //Grid.graphics.drawRect(0, 0,620-150,472);
  CurrentBackground.graphics.drawRect(0, 0, (Constants.flashWidth),Constants.flashHeight+6);
  CurrentBackground.alpha = 0.5;
  CurrentBackground.graphics.endFill();
  //End Resize
  addChild(CurrentBackground);

 Text = new TextField();
    
  Text.x = 275; Text.y = 40;
  Text.width = 140; Text.height = 30;
//   Text.background = true;
//   Text.backgroundColor = 0xFFFFFF;
  addChild(Text);
  Text.multiline = true;
  var myFormat:TextFormat = new TextFormat();
  myFormat.size = 22;
  //myFormat.align = TextFormatAlign.CENTER;
  Text.defaultTextFormat = myFormat;
  
  Text.htmlText = "<font color='#FFFFFF'>Pause Menu</font>";

  VolumeButton  = new Sprite();
  VolumeButton.graphics.beginBitmapFill(new Volume());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  VolumeButton.x = 195;
  VolumeButton.y = 150;
  VolumeButton.buttonMode = true;
  VolumeButton.addEventListener(MouseEvent.CLICK, onVolumeButtonClick);
  addChild(VolumeButton);

  SoundEffectsButton  = new Sprite();
  SoundEffectsButton.graphics.beginBitmapFill(new SoundEffects());
  SoundEffectsButton.graphics.drawRect(1, 1, 98,62);
  SoundEffectsButton.x = 315;
  SoundEffectsButton.y = 160;
  SoundEffectsButton.buttonMode = true;
  SoundEffectsButton.addEventListener(MouseEvent.CLICK, onSoundEffectsButtonClick);
  addChild(SoundEffectsButton);

  
  MainMenu = new Sprite();
  MainMenu.buttonMode = true;
  MainMenu.graphics.beginFill(0x000000);
  MainMenu.graphics.lineStyle(1,0xFFFFFF);
  MainMenu.graphics.drawRect(0, 0,100,50);
  var MainMenuText = new TextField();
  MainMenuText.htmlText = "<font size='20' color='#FFFFFF'>Main Menu</font>";
  MainMenuText.selectable = false;
  MainMenuText.y =10;
  MainMenuText.mouseEnabled = false;
  MainMenu.addChild(MainMenuText);
  MainMenu.x = 280;
  MainMenu.y = 270;
  MainMenu.addEventListener(MouseEvent.CLICK, onMainMenuClick);
  addChild(MainMenu);
  }
public function renderSoundEffects(sound:Bool)
{
  if(sound)
  {
  SoundEffectsButton.graphics.clear();
  SoundEffectsButton.graphics.beginBitmapFill(new SoundEffects());
  SoundEffectsButton.graphics.drawRect(1, 1, 98 ,61);
  }
  else
  {
  SoundEffectsButton.graphics.clear();
  SoundEffectsButton.graphics.beginBitmapFill(new SoundEffectsMuted());
  SoundEffectsButton.graphics.drawRect(1, 1, 98 ,61);
  }

}
public function renderVolume(volume:Bool)
{
  if(volume)
  {
  VolumeButton.graphics.clear();
  VolumeButton.graphics.beginBitmapFill(new Volume());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  }
  else
  {
  VolumeButton.graphics.clear();
  VolumeButton.graphics.beginBitmapFill(new VolumeMuted());
  VolumeButton.graphics.drawRect(0, 0, 113 ,113);
  }

}

private function onSoundEffectsButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("SoundEffectsToggle"));
}

private function onMainMenuClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("MainMenuBack"));
}
 
private function onVolumeButtonClick(event:MouseEvent)  {
  dispatchEvent(new PauseMenuEvent("VolumeToggle"));
}

}